<?php
namespace app\admin\controller;

use think\Db;

class WebShop extends Base{
	/**
	 * [企业网店列表]
	 */
	public function webshopListInCompany() {
		if($this->request->isPost()){
			$param = input("post.");
			$limit = $param['pageSize'];
            $offset = ($param['pageNumber'] - 1) * $limit;
			$where['company_id'] = $param['companyId'];
			$return['rows'] = DB::name("webshop")
				->where($where)->limit($offset,$limit)
				->order("id desc")->select();
			$return['total'] = DB::name("webshop")->where($where)->count();
			return ['code'=>1,'msg'=>'表格加载成功','data'=>$return];
		}
		$company_id = input("get.company_id");
		$company = DB::name('users_company')->where("id",$company_id)->find();
		$this->assign([
			'Company' => $company
		]);
		return $this->fetch("webshoplist");
	}

	/**
	 * [添加网店]
	 */
	public function addWebshop() {
		$param = input("post.");
		$res = DB::name('webshop')->insert($param);
		if($res !== false){
			return ['code'=>1,'msg'=>'网店添加成功'];
		}else{
			return ['code'=>0,'msg'=>'网店添加失败'];
		}
	}

	/**
	 * [编辑网店]
	 */
	public function editWebshop() {
		$param = input("post.");
		$res = DB::name('webshop')->where('id',$param['id'])->update($param);
		if($res !== false){
			return ['code'=>1,'msg'=>'网店编辑成功'];
		}else{
			return ['code'=>0,'msg'=>'网店编辑失败'];
		}
	}

	/**
	 * [删除网店]
	 */
	public function delWebshop() {
		$param = input("post.");
		$res = DB::name('webshop')->where('id',$param['id'])->delete();
		if($res !== false){
			return ['code'=>1,'msg'=>'网店删除成功'];
		}else{
			return ['code'=>0,'msg'=>'网店删除失败'];
		}
	}
}
